﻿namespace Compass.Maui.Services;
public interface IMainPlanService
{
    Task<List<MainPlanDto>> GetMainPlansAsync(int skip,int take,string? search=null);
}

public class MainPlanService: IMainPlanService
{
    private const string ServiceName = "MainPlan";
    private readonly IHttpRestClient _client;

    public MainPlanService(IHttpRestClient client)
    {
        _client = client;
    }
    public async Task<List<MainPlanDto>> GetMainPlansAsync(int skip, int take,string? search=null)
    {
        var strSearch=string.IsNullOrEmpty(search)?"":$"&search={search}";
        var request = new BaseRequest
        {
            Method = Method.Get,
            Route = $"{ServiceName}/Maui/All?skip={skip}&take={take}{strSearch}",
        };
        var response= await _client.ExecuteAsync<List<MainPlanDto>>(request);
        return response.Status? response.Result:new List<MainPlanDto>();
    }
}